#include "Format.h"

class SimpleSelectionSort {
public:
    SimpleSelectionSort();

    ~SimpleSelectionSort();

    SimpleSelectionSort(int *arr, int num) {
        SimpleSelectionSort();
        this->sort(arr, num);
        Format::format(arr, num);
    }
private:
    int sort(int data[], int num);
};

SimpleSelectionSort::SimpleSelectionSort() {
}

SimpleSelectionSort::~SimpleSelectionSort() {
}

int SimpleSelectionSort::sort(int *arr, int n) {

    /*�Ƚ�����Ԫ�أ������ҳ���С�ķ���������ͷ��
     */
    int moveCount = 0, compareCount = 0, j, k, temp;

    for (int i = 0; i < n - 1; i++) {
        //Ѱ�ҵ�i��С��Ԫ��
        k = i; //�����ڱ����
        moveCount += 2;
        compareCount++;
        for (j = i + 1; j < n; j++) {
            if (arr[j] < arr[k])//�Ƚ��ڱ�������Ԫ�صĴ�С
            {
                k = j; //��С��Ԫ�أ���ű���
                moveCount += 2;
            }
            moveCount += 2;
            compareCount += 2;
        }
        if (k != j) {
            //����СԪ���滻ǰ��Ԫ��
            temp = arr[i];
            arr[i] = arr[k];
            arr[k] = temp;
            moveCount += 3;
            compareCount++;
        }
    }


    arr[n] += moveCount;
    arr[n + 1] += compareCount;

    return 0;
}



